package com;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

public class Daily {
    public static void main(String[] args) {
        String path = "models/测试";
        // 1. 使用类加载器获取资源文件
        String resourceName = path + "/测试.docx";
        InputStream inputStream = ClassLoader.getSystemResourceAsStream(resourceName);
        if (inputStream == null) {
            throw new RuntimeException("未找到资源文件: " + resourceName);
        }
        // 2. 加载 Word 文档
        XWPFDocument document = null;
        try {
            document = new XWPFDocument(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // 3. 提取文档内容
        List<XWPFParagraph> paragraphs = document.getParagraphs();
        System.out.println("文档中提取的文字内容：");
        for (XWPFParagraph paragraph : paragraphs) {
            String text = paragraph.getText();
            if (text != null && !text.isEmpty()) {
                System.out.println(text);
            }
        }
    }

}
